package cn.wolfcode.trip.app.interceptor;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by 13925 on 2018/10/29.
 */

/**
 * 登录拦截器
 */
public class LoginInterceptor extends HandlerInterceptorAdapter {
    //对进入的请求进行拦截
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        Object user = request.getSession().getAttribute("user_in_session");
        //如果没有用户信息
        if (user == null) {
            response.sendRedirect("/login.html");
            return false;
        }
        return true;
    }

}
